package net.cn_su.sharpeyes.utils.http;

import android.content.Context;
import android.util.Log;
import android.widget.Toast;

import com.loopj.android.http.TextHttpResponseHandler;

import net.cn_su.sharpeyes.R;


import java.util.Map;

import cz.msebera.android.httpclient.Header;

/**
 * Created by fenghao on 2015/5/29.
 */
public abstract class BaseJsonHttpResponseHandler extends TextHttpResponseHandler {

    private Context context;

    public BaseJsonHttpResponseHandler(Context context) {
        this.context = context;
    }

    @Override
    public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
        Toast.makeText(context, R.string.load_fail, Toast.LENGTH_LONG).show();

        Log.w("http", throwable.getMessage() + "---" + statusCode);
    }

    @Override
    public void onSuccess(int statusCode, Header[] headers, String responseString) {
        Map<String, Object> map = JacksonMapper.parse(responseString);
        onSuccess(statusCode, headers, map);
    }

    public void onSuccess(int statusCode, Header[] headers, Map<String, Object> map) {
        onSuccess(statusCode, map);
    }

    public void onSuccess(int statusCode, Map<String, Object> map) {

    }

}
